#include "ns.h"

extern union Nsipc nsipcbuf;

void
input(envid_t ns_envid)
{
	binaryname = "ns_input";

	// LAB 6: Your code here:
	// 	- read a packet from the device driver
	//	- send it to the network server
	// Hint: When you IPC a page to the network server, it will be
	// reading from it for a while, so don't immediately receive
	// another packet in to the same physical page.
    char buf[1518];
    int len;
    while (1) {
		
        while ((len = sys_e100_recv (buf)) < 0);
        cprintf("lalal\n");
        nsipcbuf.pkt.jp_len = len;
        memmove ((void*) nsipcbuf.pkt.jp_data, (void *) buf, len);

        ipc_send(ns_envid, NSREQ_INPUT, &nsipcbuf, PTE_U|PTE_W|PTE_P);
        sys_yield();sys_yield();sys_yield();
    }
    
}
